//
//  ListViewController.m
//  A段
//
//  Created by 潘君峰 on 15/4/10.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "ListViewController.h"
#import "ContentViewController.h"
#import "SecondViewController.h"
#import "MyConnection.h"


@interface ListViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain)NSMutableArray *tableArray;
@property (nonatomic, retain)UITableView *table;

@end

@implementation ListViewController
- (void)dealloc
{
    [_table release];
    [_tableArray release];
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        self.tableArray = [NSMutableArray array];
        NSMutableArray *array = [NSMutableArray array];
        [array addObject:@"NWES"];
        [array addObject:@"COLUMN"];
        [array addObject:@"OPINON"];
        [array addObject:@"FEATURE"];
        [array addObject:@"EVENTS"];

        [self.tableArray addObject:array];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTable];
}
#warning 创建tableView
- (void)createTable
{
    _table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.height - 64 - 49) style:UITableViewStylePlain];
    //行高
    [_table setRowHeight:100];
    
    _table.delegate = self;
    _table.dataSource = self;
    [self.view addSubview:_table];
    [_table release];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[_tableArray objectAtIndex:section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentify = @"hello";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentify]autorelease];
    }
    //取小数组
    NSArray *array = [_tableArray objectAtIndex:indexPath.section];
    //从小数组里面取行
    NSString *str = [array objectAtIndex:indexPath.row];
    //赋值
    [cell.textLabel setText:str];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    if (indexPath.row == 0) {
//        [self.navigationController dismissViewControllerAnimated:YES completion:nil];
//        SecondViewController *second = [[[SecondViewController alloc] init]autorelease];
//        [self.navigationController pushViewController:second animated:YES];
//    } else{
//        ContentViewController *content = [[ContentViewController alloc] init];
//        NSArray *array = [_tableArray objectAtIndex:indexPath.section];
//        NSDictionary *dic1 = [array objectAtIndex:indexPath.row];
//        content.dic =dic1;
//        [self.navigationController pushViewController:content animated:YES];
//    }
    
    
    ContentViewController *content = [[[ContentViewController alloc] init]autorelease];
    //传row的值
    content.num = indexPath.row;
    NSArray *array = [_tableArray objectAtIndex:indexPath.section];
    NSDictionary *dic1 = [array objectAtIndex:indexPath.row];
    content.dic =dic1;
    [self.navigationController pushViewController:content animated:YES];

}



@end
